package etc.com.market;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class SubproductAct extends Activity implements OnItemClickListener {
	/** Called when the activity is first created. */
	private ListView lv;
	ArrayList<String> arrtext = new ArrayList<String>();

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.listitem);

		TextView view = (TextView) findViewById(R.id.btnNext);
		view.setText("Drink");

		lv = (ListView) findViewById(R.id.listview);
		lv.setTextFilterEnabled(true);
		lv.setOnItemClickListener(this);
		lv.setAdapter(new ImageAdapter(this));

		arrtext.add("Wine");
		arrtext.add("Beverage");

	}

	
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		// Toast.makeText(this, "CHON:"+arg2, Toast.LENGTH_SHORT).show();
		// Intent intent = new Intent(this, SpecifyProduct.class);
		// startActivity(intent);
		switch (arg2) {
		case 0:
			Intent WineAct = new Intent(this, WineAct.class);
			startActivity(WineAct);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);
			break;
		case 1:
			Intent BeverageAct = new Intent(this, BeverageAct.class);
			startActivity(BeverageAct);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);
			break;
		case 2:
			break;
		}

	}

	public class ImageAdapter extends BaseAdapter {
		private Context mContext;

		public ImageAdapter(Context c) {
			mContext = c;
		}

		public int getCount() {
			return arrtext.size();
		}

		public Object getItem(int position) {
			return null;
		}

		public long getItemId(int position) {
			return 0;
		}

		// create a new ImageView for each item referenced by the Adapter
		public View getView(int position, View convertView, ViewGroup parent) {
			LayoutInflater inflater = LayoutInflater.from(mContext);

			View row = inflater.inflate(R.layout.category, parent, false);

			TextView label = (TextView) row.findViewById(R.id.namefile);

			label.setText(arrtext.get(position));

			return row;
		}
	}
}